<?php
/*
 * Combo SQL.
 * @Autor: Inicial.cl.
 */
class ComboSQL {
  public static function obtenerQuery($tipo, $filtradoPorId){
    $query = "";

    switch ($tipo) {
      case "Estado":
        $query = "
                  SELECT
                    id AS Valor,
                    nombre AS Texto
                  FROM
                    estado
                  WHERE
                      (-1 = ".$filtradoPorId." OR id = ".$filtradoPorId.")
                  AND id > 0
                  ORDER BY
                    Texto;
                 ";
        break;

      case "TipoComentario":
        $query = "
                  SELECT
                    id AS Valor,
                    nombre AS Texto
                  FROM
                    tipo_comentario
                  WHERE
                    (-1 = ".$filtradoPorId." OR id = ".$filtradoPorId.")
                  ORDER BY
                    Texto;
                 ";
        break;

      case "Sexo":
      case "Nacionalidad":
      case "Ojos":
      case "Piel":
      case "Pelo":
        $query = "
                  SELECT
                    valor AS Valor,
                    nombre AS Texto
                  FROM
                    tipo_general
                  WHERE
                      tipo = '".$tipo."'
                  AND activo = 1
                  ORDER BY
                    Texto;
                 ";
        break;

      case "Profesion":
        $query = "
                  SELECT
                    id AS Valor,
                    nombre AS Texto
                  FROM
                    profesion
                  WHERE
                    (-1 = ".$filtradoPorId." OR id = ".$filtradoPorId.")
                  ORDER BY
                    Texto;
                 ";
        break;

      case "Comuna":
        $query = "
                  SELECT
                    id AS Valor,
                    nombre AS Texto
                  FROM
                    comuna
                  WHERE
                    (-1 = ".$filtradoPorId." OR id = ".$filtradoPorId.")
                  ORDER BY
                    Texto;
                 ";
        break;

      case "TipoUsuario":
        $query = "
                  SELECT
                    id AS Valor,
                    nombre AS Texto
                  FROM
                    tipo_usuario
                  WHERE
                    (-1 = ".$filtradoPorId." OR id = ".$filtradoPorId.")
                  ORDER BY
                    Texto;
                 ";
        break;

      case "Escort":
        $query = "
                  SELECT
                    e.id AS Valor,
                    e.nombre AS Texto
                  FROM
                    escort as e
                    inner join usuario as u on (e.idUsuario = u.id)
                  WHERE
                      (-1 = ".$filtradoPorId." OR e.id = ".$filtradoPorId.")
                  AND u.idEstado = 1
                  ORDER BY
                    Texto;
                 ";
        break;

      case "Region":
        $query = "
                  SELECT
                    id AS Valor,
                    nombre AS Texto
                  FROM
                    region
                  WHERE
                    (-1 = ".$filtradoPorId." OR id = ".$filtradoPorId.")
                  ORDER BY
                    id;
                 ";
        break;

      case "ComunasPorRegion":
        $query = "
                  SELECT
                    id AS Valor,
                    nombre AS Texto
                  FROM
                    comuna
                  WHERE
                    (-1 = ".$filtradoPorId." OR idRegion = ".$filtradoPorId.")
                  ORDER BY
                    Texto;
                 ";
        break;

      case "UsuarioEscort":
        $query = "
                  SELECT
                    e.idUsuario AS Valor,
                    e.nombre AS Texto
                  FROM
                    escort as e
                    inner join usuario as u on (e.idUsuario = u.id)
                  WHERE
                      (-1 = ".$filtradoPorId." OR e.id = ".$filtradoPorId.")
                  AND u.idEstado = 1
                  ORDER BY
                    Texto;
                 ";
        break;


      default:
        $query = "";
        break;
    }
    return $query;
  }

}
?>